$(document).ready(function() {	
	$.cookie('PLACE_LOAD_IMG',1);
});
function showContent(intId) {
	$('.sSummary .content').hide();
	$('.sSummary a').removeClass('active');
	$('#menuPlace' + intId).addClass('active');
	if(intId == 1) {
		$('#showImg').show();
	}else if(intId == 4) {
		$('#showContact').show();
	}else if(intId == 5) {
		$('#showPromote').show();
	}
}
uiImage	= function(intPlaceId) {
	$.getJSON(				
		HOST_VFRIEND + 'ajax/uipimage?placeid='+intPlaceId+'&callback=?',		
		function(response) {	
			if(response['error'] == 0) {				
				$.blockUI({
					message: response['dhtml'], 
					css: { 
						textAlgin:'left',
						background:'none',
						border: 'none',
						width:'400px', 
						top: (($(window).height()-400)/2) + 'px', 
						left:(($(window).width()-400)/2) + 'px',
						cursor: 'default',
						zIndex: '10001'
					},
					overlayCSS: {
						cursor: 'default',
						zIndex: '10000'
					}
				});
			} else {
				var msg	= response['msg'];
				alert(msg);
			}
		}
	);
}
uiRating = function(intPlaceId) {
	$.getJSON(				
		HOST_VFRIEND + 'ajax/uipcmt?placeid='+intPlaceId+'&callback=?',		
		function(response) {	
			if(response['error'] == 0) {				
				$.blockUI({
					message: response['dhtml'], 
					css: { 
						textAlgin:'left',
						background:'none',
						border: 'none',
						width:'400px', 
						top: (($(window).height()-400)/2) + 'px', 
						left:(($(window).width()-400)/2) + 'px',
						cursor: 'default',
						zIndex: '10001'
					},
					overlayCSS: {
						cursor: 'default',
						zIndex: '10000'
					}
				});
			} else {
				var msg	= response['msg'];
				alert(msg);
			}
		}
	);
}
function likePlace(intVal) {	
	$.getJSON(				
		HOST_VFRIEND + 'comment/place?act=1&placeid='+intVal+'&callback=?',		
		function(response) {					
			if(response['error'] == 0) {						
				showUIMessage(response['msg']);
				$('#boxLike').html(response['data']);
			} else {
				alert(response['msg']);
			}
		}
	);
}
function likeImage(intPlaceId, intVal) {	
	$.getJSON(				
		HOST_VFRIEND + 'ajax/placeimg?type=3&placeid='+intPlaceId+'&pimageid='+intVal+'&callback=?',		
		function(response) {					
			if(response['error'] == 0) {						
				showUIMessage(response['msg']);
				$('#ilike').html(response['like']);
			} else {
				alert(response['msg']);
			}
		}
	);
}
deleteImg = function(intPlaceId, intPimageId, strToken) {
	if(confirm(image_delete_confirm) == true) {
		document.location.href = HOST_VFRIEND + 'place/delimg?pimageid='+intPimageId+'&token='+strToken+'&placeid='+intPlaceId;
	} 
	return false;
}
function updContact(intPlaceId, intAct) {
	var oEditorContact 	= FCKeditorAPI.GetInstance('pcontact') ;
	var strContact		= stripTags(oEditorContact.GetXHTML( true ),3);
	updPlace(intPlaceId, intAct, strContact);
}

function updPromotion(intPlaceId, intAct) {
	var oEditorPromotion 	= FCKeditorAPI.GetInstance('ppromotion') ;
	var strPromotion		= stripTags(oEditorPromotion.GetXHTML( true ),3);
	updPlace(intPlaceId, intAct, strPromotion);
}

function updMap(intPlaceId, intAct) {
	/*var oEditorMap 	= FCKeditorAPI.GetInstance('pmap') ;
	var strMap		= stripTags(oEditorMap.GetXHTML( true ),3);	*/
	var strMap = $('#pmap').val();	
	updPlace(intPlaceId, intAct, strMap);
}

function updPlace(intPlaceId, intAct, strContent) {	
	$.post(
       HOST_VFRIEND + 'comment/placeupd',	
       {act: intAct, placeid: intPlaceId, content: strContent},
	   function(response) {			
							
			if(response.error == 0) {						
				showUIMessage(response.msg);
				if(intAct == 3)
					$('#showMap').html(response.data);
				else if(intAct == 4)
					$('#showContact').html(response.data);
				else if(intAct == 6)
					$('#showPromote').html(response.data);
				
			} else {
				alert(response.msg);
			}
		},
		"json"
	);
}
onMouseOverForCmt = function(intId) {
	$('#rowCmt' + intId).show();
}
onMouseOutForCmt = function(intId) {
	$('#rowCmt' + intId).hide();
}
onMouseOverForImgInfo = function() {
	$('.boxDetail td.img .info').show();
}
onMouseOutForImgInfo = function(intId) {
	$('.boxDetail td.img .info').hide();
}
loadImg = function(intId) {		
	if($.cookie('PLACE_LOAD_IMG') == 1) {
		$.cookie('PLACE_LOAD_IMG', 0);
		$('.boxDetail td.img').append('<div class="loading"><p align="center"><img src="'+HOST_STATICS+'img/bg/loading-bar.gif" alt="loading" width="88" height="7" border="0" /></p><p align="center">'+image_uploading+'.</p><p>&nbsp;</p></div>');	
		$.getJSON(				
			HOST_VFRIEND + 'ajax/placeimg?type=2&pimageid='+intId+'&callback=?',		
			function(response) {	
				$('.boxDetail td.img .loading').remove();				
				$('.boxDetail td.img').html(response['dhtml']);	
				$.cookie('PLACE_LOAD_IMG', 1);
			}
		);	
	}
}
uploadImage = function(strToken) {
	$strImage	= $('#pimage').val();
	intPlaceId	= $('#pplaceid').val();
	strNote		= $('#pnote').val();
	if(!validateImage($strImage)) {
		alert(image_format);
		return false;
	}
	if(!validateImgSize('pimage')) {
		alert(image_size);
		return false;
	}
	var msg = 	'<p align="center"><img src="'+HOST_STATICS+'img/bg/loading-bar.gif" alt="loading" width="88" height="7" border="0" /></p><p align="center">'+image_uploading+'.</p><p>&nbsp;</p>';
	$.blockUI({
		message: msg, 
		css: {
			width:'330px', 
			top: (($(window).height()-100)/2) + 'px', 
			left:(($(window).width()-300)/2) + 'px',
			zIndex: 10001,
			cursor: 'default'
		}, 
		overlayCSS: {
			zIndex: 10000,
			cursor: 'default'
		}
	});
	
	$.ajaxFileUpload ({
		url:			HOST_VFRIEND + 'ajax/uiplaceimg?token='+strToken+'&pplaceid='+intPlaceId+'&pnote='+strNote,
		secureuri:		false,
		fileElementId:	'pimage',
		dataType: 		'json',
		data:{
			name:'logan', 
			id:'id'
		},
		success: function (data, status)
		{
			if(typeof(data.error) != 'undefined')
			{
				var strMsg = data.msg;
				closeUI();
				$('#pimage').val('');
				$('#pnote').val('');							
				if(data.error == 0) {
					$.getJSON(				
						HOST_VFRIEND + 'ajax/placeimg?placeid='+intPlaceId+'&callback=?',		
						function(response) {					
							$('#showImg').html(response['dhtml']);							
						}
					);
					closeUI();				
				} else {
					closeUI();
					alert(strMsg);
				}
			}
		},
		error: function (data, status, e)
		{		
			closeUI();				
			alert(image_error);
			alert(data.responseText);			
		}
	});
}

$('#menuPlace2').click(function(){
	var intPlaceId = $('#pplaceid').val();
	$.getJSON(				
		HOST_VFRIEND + 'ajax/placeimg?placeid='+intPlaceId+'&callback=?',		
		function(response) {					
			$('#showImg').html(response['dhtml']);
			showContent(2);							
		}
	);
});

$('#menuPlace3').click(function(){
	var intPlaceId = $('#pplaceid').val();
	$.getJSON(				
		HOST_VFRIEND + 'ajax/placemap?placeid='+intPlaceId+'&callback=?',		
		function(response) {					
			$('#showMap').html(response['dhtml']);
			showContent(3);							
		}
	);
});
